package swd.work.dataview_wizard_fld_show;

import com.pub.database.*;
import java.util.*;

public class Business {
   QueryBean gqbnDAO=null;
   public Business(QueryBean pqbnDAO){
      gqbnDAO=pqbnDAO;
   }
   String selectTableDataToFld(View view) throws Exception {
      String lstrSQL=null;
      Hashtable<String,Object> lhtTableData=null;
      try{
         lstrSQL="select prg_no,html_text,field_name from dataview_wizard_fld_show where prg_no='" + view.getprg_no() + "'";
         lhtTableData=gqbnDAO.readSingleRowData(lstrSQL);
         if(lhtTableData==null){
            return "查無資料";
         }
         view.setprg_no(String.valueOf((lhtTableData.get("PRG_NO").toString())));
         view.sethtml_text(String.valueOf((lhtTableData.get("HTML_TEXT").toString())));
         view.setfield_name(String.valueOf((lhtTableData.get("FIELD_NAME").toString())));

         return "";
      }
      catch(Exception e){
         throw new Exception(e.toString());
      }
      finally{
         lhtTableData.clear();
         lhtTableData=null;
      }
   }
   String exeUpdSQL(View view) throws Exception{
      String lstrSQL=new String();
      Vector<Object> lvtrParam = new Vector<Object>();
      try{
         lvtrParam.add(view.getprg_no()==null ? null :String.valueOf(view.getprg_no()));
         lvtrParam.add(view.gethtml_text()==null ? null :String.valueOf(view.gethtml_text()));
         lvtrParam.add(view.getfield_name()==null ? null :String.valueOf(view.getfield_name()));
         lstrSQL="update dataview_wizard_fld_show set prg_no=?,html_text=?,field_name=? where prg_no='" + view.getprg_no() + "'";
         if(!gqbnDAO.executeSQL(lstrSQL,lvtrParam)){
            return "dataview_wizard_fld_show";
         }
         return "";
      }
      catch(Exception e){
         e.printStackTrace();
         throw new Exception(e.toString());
      }
      finally{
         lvtrParam.clear();
      }
   }
   String exeInsSQL(View view) throws Exception{
      String lstrSQL=new String();
      Vector<Object> lvtrParam = new Vector<Object>();
      try{
         lvtrParam.add((view.getprg_no()==null ? null : view.getprg_no()));
         lvtrParam.add((view.getfield_name()==null ? null : view.getfield_name()));
         lvtrParam.add((view.gethtml_text()==null ? null : view.gethtml_text()));
         lstrSQL="insert into dataview_wizard_fld_show(prg_no,field_name,html_text) values (?,?,?)";
         if(!gqbnDAO.executeSQL(lstrSQL,lvtrParam)){;
            return "dataview_wizard_fld_show";
         }
         lvtrParam.clear();

         return "";
      }
      catch(Exception e){
         e.printStackTrace();
         throw new Exception(e);
      }
      finally{
         lvtrParam.clear();
      }
   }
   String checkNotNullFld(View view) throws Exception{
      StringBuffer lstbNullFldList=new StringBuffer();
      return (lstbNullFldList.toString().equals("") ? "" : lstbNullFldList.delete(lstbNullFldList.length()-1,lstbNullFldList.length()).toString());
   }
   void setInitValueForAdd(View view,String pstrUserID) throws Exception{
   }
   void setReadonlyForAdd(View view) throws Exception{
   }
}
